import { _decorator, CCString, Component, Event, Label, Node, Sprite, Texture2D, SpriteFrame, ImageAsset } from 'cc';
import { Logger } from 'db://assets/util';

const { ccclass, property, menu } = _decorator;

export class PropEvent extends Event {
    constructor(name: string, bubbles?: boolean, public detail?: LDChapter.ChildFrame) {
        super(name, bubbles);
    }
}

@ccclass('PropItem')
@menu('prop/PropItem')
export class PropItem extends Component {
    #logger = new Logger('道具项::PropItem')

    prop: LDChapter.ChildFrame

    @property(SpriteFrame)
    normalBG: SpriteFrame;

    @property(SpriteFrame)
    activeBG: SpriteFrame;

    @property(Sprite)
    propNode: Sprite;

    @property(Label)
    labelNode: Label;

    @property(Label)
    priceNode: Label;

    get bg() {
        return this.getComponent(Sprite)
    }

    start() {

    }

    onTap(event: Event, customEventData: string) {
        this.bg.spriteFrame = this.activeBG
        this.#logger.debug('@onTap::点击道具选项', event, customEventData)
        this.node.dispatchEvent(new PropEvent('prop', true, this.prop))
    }
}
